﻿using System;
using System.Collections.Generic;
using Model;
using System.Xml;
using Common;
namespace Controller
{
   public class ControlSelectorBO
    {

        /// <summary>
        /// 获取字段对应的可选控件列表，用于填充GridView
        /// </summary>
        /// <param name="xmlPath"></param>
        /// <returns></returns>
        public List<exFieldControlInfo> GetFieldToControlList(string ConfigName)
        {
            List<exFieldControlInfo> list = null;
            exFieldControlInfo fieldControl = null;
            try
            {
                list = new List<exFieldControlInfo>();
                XmlDocument doc=new XmlDocument();
                doc.Load(PubConstant.ConfigPath + PubConstant.FieldToControlName);
                XmlDocument doc2 =new XmlDocument();
                doc2.Load(PubConstant.ConfigPath + PubConstant.ControlPrefixName);

                List<exFieldInfoChild> fieldList=ServerExplorerDAO.GetBuildFieldInfoByConfigName(PubConstant.ConfigPath,PubConstant.ServerBuildConfigName, ConfigName);
                fieldList.ForEach(fic =>
                {
                    fieldControl = new exFieldControlInfo();
                    fieldControl.FieldType = fic.FieldType;
                    fieldControl.FieldName = fic.FieldName;
                    fieldControl.FieldDescription = fic.Description;
                    fieldControl.ControlList = ServerExplorerDAO.GetControlListByFieldType(doc, doc2, fic.FieldType);
                    list.Add(fieldControl);
                });
            }
            catch(Exception ex )
            {
                throw ex;
            }
            return list;
        }

    }
}
